/**
 * 池底
 * @author lmzd
 */
function pot(r_user_arr,r_pot) {
	/*
	 * 競爭底池的玩家,默認已排好序
	 */ 
	this._user_arr = r_user_arr;
	/*
	 * 底池金額
	 */ 
	this._pot = r_pot;
	/*
	 * 取得池底玩家數組
	 */ 
	this.getUserArr = function() {
		return this._user_arr;				
	}
	/*
	 * 取得池底金額
	 */ 
	this.getPot = function() {
		return this._pot;					
	}
	/*
	 *判斷是否公用一個彩池 
	 */	
	this.checkMerge = function(r_user_arr) {
		if ( this._user_arr.length < 1 ) {
			return false;
		}
		//r_user_arr = arraySort(r_user_arr,'asc');
		if ( this._user_arr.length == r_user_arr.length ) {				
			for ( var i in r_user_arr) {
				if ( r_user_arr[i] != this._user_arr[i] ) {
					return false;
				}
			}
			return true;
		}
		return false;		
	}
	/*
	 *公用彩池，並返回纍計彩金 
	 */	
	this.mergePot = function(r_pot) {
		this._pot += r_pot;
		return this._pot;				
	}
	/*
	 * 分派彩金
	 */ 
	this.sharePot = function(r_user_id) {
		if (typeof(r_user_id) == 'object') {
			var _pot = Math.floor(this._pot / (r_user_id.length));
			for each(var _user_id in r_user_id) {
				this.dealPot(_user_id,_pot)
			}
		}else {
			this.dealPot(r_user_id);
		}
	}
	this.dealPot = function(r_user_id,r_pot) {
		if ( in_array(r_user_id, this._user_arr) ) {	
			var _user = _server.getUserById(r_user_id);
			//增加桌上筹码
			userBet(_user, r_pot, 1);			
		}
	}
	/**
	 * 玩家棄牌,之前參與的分池全部取消資格
	 */
	this.fold = function( r_user_id ) {
		for ( var i in this._user_arr ) {
			if ( this._user_arr[i] == r_user_id ) {
				this._user_arr.splice(i, 1);
				break;
			}
		}		
	}	
	//取得彩池的内置数据
	this.getVal = function() {
		return [this._user_arr, this._pot];
	}
	
}